﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml.Linq;

namespace ch03.sender
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri listen_uri = new Uri("http://127.0.0.1:3000/listener");
            Binding binding = new BasicHttpBinding();
            IChannelFactory<IRequestChannel> channel_factory = binding.BuildChannelFactory<IRequestChannel>();
            channel_factory.Open();

            IRequestChannel channel = channel_factory.CreateChannel(new EndpointAddress(listen_uri));
            channel.Open();
            Message replay_message = channel.Request(CreateReplyMessage(binding));
            Console.WriteLine(replay_message);
            Console.Read();

        }

        static Message CreateReplyMessage(Binding binding)
        {
            string action = "http://www.progamming-wcf.com/calculatorservice/AddResponse";
            XNamespace ns = "http://www.progamming-wcf.com";
            XElement body = new XElement(new XElement(ns + "AddResponse", new XElement(ns + "x", 1), new XElement(ns + "x", 2)));
            return Message.CreateMessage(binding.MessageVersion, action, body);
        }
    }
}
